package cn.edu.henu.team.ui_login;

import androidx.viewpager.widget.ViewPager;
import cn.edu.henu.team.R;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.youth.banner.Banner;
import com.youth.banner.loader.ImageLoader;

import java.util.ArrayList;
import java.util.List;

public class GuideActivity extends BaseActivity {

    Banner banner;
    Button bt_start;
    private List<Integer> imageList;

    @Override
    protected int initLayout() {
        return R.layout.activity_guide;
    }

    @Override
    protected void initData() {
        initUI();

        initBannerData(); //轮播加载图片

        initViews();
    }

    @Override
    protected void initView() {

    }

    private void initUI() {
        banner = findViewById(R.id.banner);
        bt_start = findViewById(R.id.bt_start);
    }

    // 初始化banner数据
    private void initBannerData() {
        imageList = new ArrayList<>();
        imageList.add(R.drawable.pic1);
        imageList.add(R.drawable.pic2);
        imageList.add(R.drawable.pic3);
        imageList.add(R.drawable.pic4);
    }

    private void initViews() {
        banner.setImageLoader(new ModelImageLoader())
                .setImages(imageList)
                .isAutoPlay(false)
                .start();


        banner.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i1) {
            }

            @Override
            public void onPageSelected(int i) {
                if (i == imageList.size() - 1) {
                    bt_start.setVisibility(View.VISIBLE);
                    bt_start.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            startActivity(new Intent(GuideActivity.this, LoginActivity.class));
                            finish();
                        }
                    });
                } else {
                    bt_start.setVisibility(View.GONE);
                }
            }

            @Override
            public void onPageScrollStateChanged(int i) {
            }
        });
    }

    protected class ModelImageLoader extends ImageLoader {
        @Override
        public void displayImage(Context context, Object path, ImageView imageView) {
            Glide.with(context)
                    .load(path)
                    .into(imageView);
        }
    }
}


